import 'package:flutter/material.dart';

import 'package:lottie/lottie.dart';
import 'package:top_foundation/utils/util.dart';

class EmptyView extends StatelessWidget {
  const EmptyView({
    super.key,
    this.top,
    this.title = '暂无数据',
    this.url,
    this.onTap,
    this.isLottie = false,
  });
  final double? top;
  final String title;
  final String? url;
  final bool isLottie;
  final Function()? onTap;

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (p0, p1) {
        var height = p1.biggest.width;
        return Container(
          alignment: Alignment.center,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              // Container(
              //   height: top ?? height * 0.05,
              // ),
              isLottie
                  ? LottieBuilder.asset(
                      url ?? '',
                      height: height * 0.6,
                      fit: BoxFit.contain,
                    )
                  : loadImage(
                      url: url ?? TopConfig.imgEmpty,
                      width: height * 0.6,
                      fit: BoxFit.fitWidth,
                    ),
              SizedBox(
                height: 20.r,
              ),
              TextButton(
                onPressed: onTap,
                child: Text(
                  title,
                  style: TextStyle(
                      color: onTap == null
                          ? const Color(0xff999999)
                          : Colors.green,
                      fontSize: 13.sp),
                ),
              ),
              SizedBox(
                height: height * 0.1,
              ),
            ],
          ),
        );
      },
    );
  }
}
